import time
from lib2to3.pgen2 import driver

from selenium.webdriver.chrome import webdriver
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.common.by import By

from pages.basePage import BasePage
from pages.ecShopLoginPages import Login

# driver = webdriver.WebDriver()
# driver.get('http://192.168.109.131/user.php?act=message_list')
# driver.maximize_window()

class MsgPage(BasePage):
    # 属性
    myLiuyan = (By.LINK_TEXT,'我的留言')
    zhuti = (By.NAME, 'msg_title')
    neirong = (By.NAME, 'msg_content')
    file = (By.NAME, 'message_img')
    tijiao = (By.CLASS_NAME, 'bnt_bonus')
    delete1 = (By.XPATH,"//div[@class='userCenterBox boxCenterList clearfix']//a[1]")
    enum=(By.CSS_SELECTOR,"#pager>.f_l >b")
    def liuyan(self,etitle='货不对板',econent='awufbabfaihdiuwa',efile=r'D:\Pycharm-work\webAutoECshop\pages\1r.jpg'):
        # 行为
        # 获取当前留言数量
        self.begin_num = self.getEleTxt(self.findEle(self.enum))
        # 点击我的留言
        self.eleClick(self.findEle(self.myLiuyan))
        # 输入主题
        self.inpuText(self.findEle(self.zhuti),etitle)
        # 输入内容
        self.inpuText(self.findEle(self.neirong), econent)
        # 选择文件
        self.findEle(self.file).send_keys(efile)
        # 点击提交
        self.eleClick(self.findEle(self.tijiao))
        time.sleep(2)
    # 删除留言
    def delMsg(self):
        # 点击我的留言
        self.eleClick(self.findEle(self.myLiuyan))
        # 删除留言
        self.eleClick(self.findEle(self.delete1))
        time.sleep(2)
        # 切换为弹窗页面
        alert: Alert = self.driver.switch_to.alert  # 需通过该弹窗对象进行操作
        alert.accept()
    # 添加留言
    def addMsg(self):
        # 已经是ok的情况
        # 获取执行后的数量
        end_num = self.getEleTxt(self.findEle(self.enum))
        return self.begin_num,end_num
    # 为空的情况
    def addErrorNone(self):
        t = self.getAlertTxt()
        return t
# if __name__ == '__main__':
#     a= MsgPage()
#     a.denglu()
#     # a.liuyan()
#     a.delMsg()